<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
        content="width=device-width, initial-scale=1.0">
<meta name="HandheldFriendly" content="true">
<title>Sample</title>
</head>
<body>
<script>
if (window.Worker){
  // 使用构造方法创建Worker，构造方法的参数是要执行的JavaScript文件URL
  var worker = new Worker('worker.js');
  // 注册error事件监听Worker出错
  worker.onerror = function(e){  
	 alert("于第["+ e.lineno +"]行发生错误 : " + e.message);
  } 

  // 注册message事件监听Worker返回的数据，如果有数据返回就写到网页上
  worker.onmessage = function (event){
     var result = event.data;
	 document.writeln(result + "<br />");
  };
} else {
  alert("浏览器不支持Web Workers!");
}
</script>
</body>
</html>
